const express = require('express')
const router = express()
const { filterQuery, queryData, assemQuery, assemArrays, accData,vagFind } = require('../util/index')


/* 配置数据库 */


/* 表格模板页 */
router.get('/test/getWangsTable', async (req, res) => {
    let queryArrays = await filterQuery(req.query)
    let keys = queryArrays.filter(el => { return el != 'pageNo' && el != 'pageSize' })
    if (queryArrays.length !== 2) {
        /* 精确查询 */
        /* let sql = 'select * from usertest where '
        const a = await assemQuery(sql, keys)
        const b = await assemArrays(keys, req.query)
        const str = a.sql
        accData(str, b, req, res) */
        /* 模糊查询 */
        vagFind(keys,req.query)

    }
    /* 全部查询 */
    else {
        queryData('select * from usertest limit ?,?;select count(*) from usertest', req, res)
    }
})

module.exports = router